﻿using System;
using ReactiveUI;

namespace GetStartedApp.ViewModels
{
    public class UserViewModel : ViewModelBase
    {
        public UserViewModel()
        {
            _age = 10;
            this.WhenAnyValue(x => x.Name, x => x.Age)
                .Subscribe(a => this.RaisePropertyChanged(nameof(Greeting)));
        }
        private string _name;
        public string Name
        {
            get => _name;
            set => this.RaiseAndSetIfChanged(ref _name, value);
        }

        private int _age;
        public int Age
        {
            get => _age;
            set => this.RaiseAndSetIfChanged(ref _age, value);
        }

        public string Greeting
        {
            get
            {
                if (string.IsNullOrEmpty(Name))
                {
                    return "Hello, Guest222!";
                }
                else
                {
                    return $"Hello, {Name}! You are {Age} years old.";
                }
            }
        }
    }
}
